/** 
 * æ°å­å¸®å©ç±»
 * @author kehailin
 * @time 2018/12/8
 */

var numberUtils = {
		/*éæºæ°èå´*/  
		random:function (min, max) {  
		    if (arguments.length === 2) { 
		        return Math.floor(min + Math.random() * ( (max+1) - min ))  
		    }else{  
		        return null;  
		    }  
		}  ,
		 
		/*å°é¿æä¼¯æ°å­ç¿»è¯æä¸­æçå¤§åæ°å­*/  
		numberToChinese:function (num) {  
		    var AA = new Array("é¶", "ä¸", "äº", "ä¸", "å", "äº", "å­", "ä¸", "å«", "ä¹", "å");  
		    var BB = new Array("", "å", "ç¾", "ä»", "è¬", "å", "ç¹", "");  
		    var a = ("" + num).replace(/(^0*)/g, "").split("."),  
		        k = 0,  
		        re = "";  
		    for(var i = a[0].length - 1; i >= 0; i--) {  
		        switch(k) {  
		            case 0:  
		                re = BB[7] + re;  
		                break;  
		            case 4:  
		                if(!new RegExp("0{4}//d{" + (a[0].length - i - 1) + "}$")  
		                    .test(a[0]))  
		                    re = BB[4] + re;  
		                break;  
		            case 8:  
		                re = BB[5] + re;  
		                BB[7] = BB[5];  
		                k = 0;  
		                break;  
		        } 
		 
		        if(k % 4 == 2 && a[0].charAt(i + 2) != 0 && a[0].charAt(i + 1) == 0)  
		            re = AA[0] + re;  
		        if(a[0].charAt(i) != 0)  
		            re = AA[a[0].charAt(i)] + BB[k % 4] + re;  
		        k++; 
		     }  
		 
		    if(a.length > 1) // å ä¸å°æ°é¨å(å¦ææå°æ°é¨å)  
		    {  
		        re += BB[6];  
		        for(var i = 0; i < a[1].length; i++)  
		            re += AA[a[1].charAt(i)];  
		    }  
		    if(re == 'ä¸å')  
		        re = "å";  
		    if(re.match(/^ä¸/) && re.length == 3)  
		        re = re.replace("ä¸", "");  
		    return re;  
		},  
		 
		/*å°æ°å­è½¬æ¢ä¸ºå¤§åéé¢*/  
		changeToChinese:function (Num) {  
		        //å¤æ­å¦æä¼ éè¿æ¥çä¸æ¯å­ç¬¦çè¯è½¬æ¢ä¸ºå­ç¬¦  
		        if(typeof Num == "number") {  
		            Num = new String(Num);  
		        };  
		        Num = Num.replace(/,/g, "") //æ¿æ¢tomoney()ä¸­çâ,â  
		        Num = Num.replace(/ /g, "") //æ¿æ¢tomoney()ä¸­çç©ºæ ¼  
		        Num = Num.replace(/ï¿¥/g, "") //æ¿æ¢æå¯è½åºç°çï¿¥å­ç¬¦  
		        if(isNaN(Num)) { //éªè¯è¾å¥çå­ç¬¦æ¯å¦ä¸ºæ°å­  
		            //alert("è¯·æ£æ¥å°åéé¢æ¯å¦æ­£ç¡®");  
		            return "";  
		        };  
		        //å­ç¬¦å¤çå®æ¯åå¼å§è½¬æ¢ï¼éç¨ååä¸¤é¨ååå«è½¬æ¢  
		        var part = String(Num).split(".");  
		        var newchar = "";  
		        //å°æ°ç¹åè¿è¡è½¬å  
		        for(var i = part[0].length - 1; i >= 0; i--) {  
		            if(part[0].length > 10) {  
		                return "";  
		                //è¥æ°éè¶è¿æ¾äº¿åä½ï¼æç¤º  
		            }  
		            var tmpnewchar = ""  
		            var perchar = part[0].charAt(i);  
		            switch(perchar) {  
		                case "0":  
		                    tmpnewchar = "é¶" + tmpnewchar;  
		                    break;  
		                case "1":  
		                    tmpnewchar = "å£¹" + tmpnewchar;  
		                    break;  
		                case "2":  
		                    tmpnewchar = "è´°" + tmpnewchar;  
		                    break;  
		                case "3":  
		                    tmpnewchar = "å" + tmpnewchar;  
		                    break;  
		                case "4":  
		                    tmpnewchar = "è" + tmpnewchar;  
		                    break;  
		                case "5":  
		                    tmpnewchar = "ä¼" + tmpnewchar;  
		                    break;  
		                case "6":  
		                    tmpnewchar = "é" + tmpnewchar;  
		                    break;  
		                case "7":  
		                    tmpnewchar = "æ" + tmpnewchar;  
		                    break;  
		                case "8":  
		                    tmpnewchar = "æ" + tmpnewchar;  
		                    break;  
		                case "9":  
		                    tmpnewchar = "ç" + tmpnewchar;  
		                    break;  
		            }  
		            switch(part[0].length - i - 1) {  
		                case 0:  
		                    tmpnewchar = tmpnewchar + "å"; 
		                     break;  
		                case 1:  
		                    if(perchar != 0) tmpnewchar = tmpnewchar + "æ¾";  
		                    break;  
		                case 2:  
		                    if(perchar != 0) tmpnewchar = tmpnewchar + "ä½°";  
		                    break;  
		                case 3:  
		                    if(perchar != 0) tmpnewchar = tmpnewchar + "ä»";  
		                    break; 
		                 case 4:  
		                    tmpnewchar = tmpnewchar + "ä¸";  
		                    break; 
		                 case 5:  
		                    if(perchar != 0) tmpnewchar = tmpnewchar + "æ¾";  
		                    break; 
		                 case 6:  
		                    if(perchar != 0) tmpnewchar = tmpnewchar + "ä½°";  
		                    break; 
		                 case 7:  
		                    if(perchar != 0) tmpnewchar = tmpnewchar + "ä»";  
		                    break;  
		                case 8:  
		                    tmpnewchar = tmpnewchar + "äº¿";  
		                    break;  
		                case 9:  
		                    tmpnewchar = tmpnewchar + "æ¾";  
		                    break;  
		            }  
		            var newchar = tmpnewchar + newchar;  
		        } 
		         //å°æ°ç¹ä¹åè¿è¡è½¬å  
		        if(Num.indexOf(".") != -1) {  
		            if(part[1].length > 2) {  
		                // alert("å°æ°ç¹ä¹ååªè½ä¿çä¸¤ä½,ç³»ç»å°èªå¨æªæ­");  
		                part[1] = part[1].substr(0, 2)  
		            }  
		            for(i = 0; i < part[1].length; i++) {  
		                tmpnewchar = ""  
		                perchar = part[1].charAt(i)  
		                switch(perchar) {  
		                    case "0":  
		                        tmpnewchar = "é¶" + tmpnewchar;  
		                        break;  
		                    case "1":  
		                        tmpnewchar = "å£¹" + tmpnewchar;  
		                        break;  
		                    case "2":  
		                        tmpnewchar = "è´°" + tmpnewchar;  
		                        break;  
		                    case "3":  
		                        tmpnewchar = "å" + tmpnewchar; 
		                        break;  
		                    case "4":  
		                        tmpnewchar = "è" + tmpnewchar; 
		                        break;  
		                    case "5":  
		                        tmpnewchar = "ä¼" + tmpnewchar;  
		                        break;  
		                    case "6":  
		                        tmpnewchar = "é" + tmpnewchar;  
		                        break;  
		                    case "7":  
		                        tmpnewchar = "æ" + tmpnewchar;  
		                        break;  
		                    case "8":  
		                        tmpnewchar = "æ" + tmpnewchar;  
		                        break;  
		                    case "9":  
		                        tmpnewchar = "ç" + tmpnewchar;  
		                        break;  
		                }  
		                if(i == 0) tmpnewchar = tmpnewchar + "è§";  
		                if(i == 1) tmpnewchar = tmpnewchar + "å";  
		                newchar = newchar + tmpnewchar;  
		            }  
		        }  
		        //æ¿æ¢æææ ç¨æ±å­  
		        while(newchar.search("é¶é¶") != -1)  
		            newchar = newchar.replace("é¶é¶", "é¶");  
		        newchar = newchar.replace("é¶äº¿", "äº¿");  
		        newchar = newchar.replace("äº¿ä¸", "äº¿");  
		        newchar = newchar.replace("é¶ä¸", "ä¸");  
		        newchar = newchar.replace("é¶å", "å");  
		        newchar = newchar.replace("é¶è§", "");  
		        newchar = newchar.replace("é¶å", "");  
		        if(newchar.charAt(newchar.length - 1) == "å") {  
		            newchar = newchar + "æ´"  
		        }  
		        return newchar;  
		    } ,
		
		//æµ®ç¹æ°å æ³è¿ç®
		FloatAdd:function(arg1,arg2){
		    var r1,r2,m;
		    try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
		    try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
		    m=Math.pow(10,Math.max(r1,r2));
		    return (arg1*m+arg2*m)/m;
		},

		//æµ®ç¹æ°åæ³è¿ç®
		FloatSub:function (arg1,arg2){
		    var r1,r2,m,n;
		    try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
		    try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
		    m=Math.pow(10,Math.max(r1,r2));
		    //å¨ææ§å¶ç²¾åº¦é¿åº¦
		    n=(r1=r2)?r1:r2;
		    return ((arg1*m-arg2*m)/m).toFixed(n);
		},

		//æµ®ç¹æ°ä¹æ³è¿ç®
		FloatMul:function (arg1,arg2)
		{
		    var m=0,s1=arg1.toString(),s2=arg2.toString();
		    try{m+=s1.split(".")[1].length}catch(e){}
		    try{m+=s2.split(".")[1].length}catch(e){}
		    return Math.round(Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m));
		},


		 //æµ®ç¹æ°é¤æ³è¿ç®
		FloatDiv:function (arg1,arg2){
		    var t1=0,t2=0,r1,r2;
		    try{t1=arg1.toString().split(".")[1].length}catch(e){}
		    try{t2=arg2.toString().split(".")[1].length}catch(e){}
		    with(Math){
		        r1=Number(arg1.toString().replace(".",""));
		        r2=Number(arg2.toString().replace(".",""));
		        return Math.round((r1/r2)*pow(10,t2-t1));
		    }
		}
		
}